<%-- 
    Document   : EmployeeList
    Created on : Dec 5, 2011, 4:27:34 AM
    Author     : Michael
--%>

<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <!---
        -->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Employees</title>
    </head>
    <body>
        <input type="button" value="Home" onclick="window.location='gohome.jsp'"/>&nbsp;
          <input type="button" value="Log Out" onclick="window.location='logout.jsp'"/>
         <label><h1>All Employees</h1></label>
        <table border="1" > 

            <tr>
                    <td >Last Name</td>
                    <td >First Name</td>
                    <td >Address</td>
                    <td >Phone</td>
                    <td >Start Date</td>
                    <td >Position</td>
            </tr>
            <% 
                Connection conn = null;
                try
                {
                    conn = new DBClasses.GetConnection().getConnection();
                    String query = "SELECT EmployeeID, Lastname, Firstname, Concat(Address, ', ', City, ' ', State, ' ', Zipcode) AS Addr, "
                            + "Telephone, Startdate, Manager FROM employees ORDER BY LastName";

                    System.out.println(query);
                    java.sql.Statement stmt = conn.createStatement();
                    java.sql.ResultSet rs = stmt.executeQuery(query);



                    while(rs.next())
                    {
                        String position = "Customer Rep";
                        if(rs.getInt("Manager")==1)
                            position = "Manager";
                        if(!rs.getString("EmployeeID").equals(session.getAttribute("EmployeeID")))
                        {

            %>
            <tr>
            <td><%=rs.getString("LastName")%></td>
            <td><%=rs.getString("FirstName")%></td>
            <td><%=rs.getString("Addr")%></td>
            <td><%=rs.getString("Telephone")%></td>
            <td><%=rs.getDate("StartDate")%></td>
            <td><%=position%></td>
            </tr>
            <%
                       }
                       }
               }
               catch(Exception e)
               {
                   e.printStackTrace();
               }

               finally
               {
                   try{
                   conn.close(); }
                   catch(Exception e) {
                       e.printStackTrace();
                   }
               }
            %>
            </table>
    </body>
</html>
